home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / MiniPad / MiniPad.jar / MiniPad.class (.txt)
Encoding:
Java Class File  |  2002-01-22  |  4.9 KB  |  173 lines

  1. import javax.microedition.lcdui.Alert;
  2. import javax.microedition.lcdui.Command;
  3. import javax.microedition.lcdui.CommandListener;
  4. import javax.microedition.lcdui.Display;
  5. import javax.microedition.lcdui.Displayable;
  6. import javax.microedition.lcdui.Image;
  7. import javax.microedition.lcdui.List;
  8. import javax.microedition.lcdui.TextBox;
  9. import javax.microedition.midlet.MIDlet;
  10. import javax.microedition.rms.RecordStore;
  11.  
  12. public class MiniPad extends MIDlet implements CommandListener {
  13.    // $FF: renamed from: rs javax.microedition.rms.RecordStore
  14.    private RecordStore field_0 = null;
  15.    static int MAX_TEXT = 2000;
  16.    static byte[] bDummy = new byte[]{0, 0};
  17.    static String header = "MiniPad by RizaPN";
  18.    private Command cmExit = new Command("Exit", 7, 4);
  19.    private Command cmSaveE = new Command("Save&Exit", 1, 0);
  20.    private Command cmLine = new Command("Insert NewLine", 1, 1);
  21.    private Command cmSaveC = new Command("Save&Continue", 1, 3);
  22.    private Command cmDelete = new Command("Delete Entry", 1, 5);
  23.    private Command cmDisc = new Command("Discard", 1, 7);
  24.    private Command cmOK = new Command("OK", 7, 6);
  25.    private Command cmCancel = new Command("Cancel", 7, 7);
  26.    private Display display;
  27.    private List list00;
  28.    private Alert alert;
  29.    private TextBox text1;
  30.    private TextBox fname;
  31.    private byte nStatus;
  32.    private byte sStatus;
  33.  
  34.    public MiniPad() {
  35.       this.list00 = new List(header, 3);
  36.       this.alert = new Alert(header);
  37.       this.text1 = new TextBox(header, "", MAX_TEXT, 0);
  38.       this.fname = new TextBox("Entry Title", "", 32, 0);
  39.       this.nStatus = 0;
  40.       this.sStatus = 0;
  41.       this.display = Display.getDisplay(this);
  42.    }
  43.  
  44.    public void initlist00() {
  45.       int var1 = this.list00.size();
  46.  
  47.       while(var1 > 0) {
  48.          --var1;
  49.          this.list00.delete(var1);
  50.       }
  51.  
  52.       this.list00.append("<New Entry>", (Image)null);
  53.  
  54.       try {
  55.          String[] var2 = RecordStore.listRecordStores();
  56.  
  57.          for(int var5 = 0; var5 < var2.length; ++var5) {
  58.             this.list00.append(var2[var5], (Image)null);
  59.          }
  60.       } catch (Exception var4) {
  61.       }
  62.  
  63.    }
  64.  
  65.    protected void startApp() {
  66.       this.initlist00();
  67.       this.display.setCurrent(this.list00);
  68.       this.list00.addCommand(this.cmExit);
  69.       this.list00.setCommandListener(this);
  70.       this.text1.addCommand(this.cmSaveE);
  71.       this.text1.addCommand(this.cmSaveC);
  72.       this.text1.addCommand(this.cmDisc);
  73.       this.text1.addCommand(this.cmDelete);
  74.       this.text1.addCommand(this.cmLine);
  75.       this.fname.addCommand(this.cmOK);
  76.       this.fname.addCommand(this.cmCancel);
  77.    }
  78.  
  79.    public void commandAction(Command var1, Displayable var2) {
  80.       byte var3 = 9;
  81.       if (var1 == this.cmExit) {
  82.          this.destroyApp(false);
  83.       } else if (var1 != this.cmOK && var1 != this.cmCancel && var1 != this.cmDisc) {
  84.          if (var1 != this.cmSaveE && var1 != this.cmSaveC) {
  85.             if (var1 == this.cmDelete) {
  86.                String var12 = this.fname.getString();
  87.  
  88.                try {
  89.                   RecordStore.deleteRecordStore(var12);
  90.                } catch (Exception var9) {
  91.                }
  92.  
  93.                this.commandAction(this.cmDisc, (Displayable)null);
  94.             } else if (var1 == this.cmLine) {
  95.                this.text1.insert("\n", this.text1.getCaretPosition());
  96.             } else {
  97.                int var15 = this.list00.getSelectedIndex();
  98.                String var13 = this.list00.getString(var15);
  99.                this.fname.setString("");
  100.                this.text1.setString("");
  101.  
  102.                try {
  103.                   this.field_0 = RecordStore.openRecordStore(var13, false);
  104.                   this.fname.setString(var13);
  105.                   var13 = new String(this.field_0.getRecord(1));
  106.                   this.text1.setString(var13);
  107.                } catch (Exception var8) {
  108.                }
  109.  
  110.                try {
  111.                   this.field_0.closeRecordStore();
  112.                } catch (Exception var7) {
  113.                }
  114.  
  115.                this.display.setCurrent(this.text1);
  116.                this.text1.setCommandListener(this);
  117.                this.sStatus = 0;
  118.             }
  119.          } else {
  120.             if (var1 == this.cmSaveC) {
  121.                this.nStatus = var3;
  122.             }
  123.  
  124.             this.display.setCurrent(this.fname);
  125.             this.fname.setCommandListener(this);
  126.          }
  127.       } else {
  128.          if (var1 == this.cmOK) {
  129.             try {
  130.                String var4 = this.fname.getString();
  131.                if (var4.charAt(0) == '<') {
  132.                   return;
  133.                }
  134.  
  135.                this.field_0 = RecordStore.openRecordStore(var4, true);
  136.                if (this.field_0.getNumRecords() == 0) {
  137.                   this.field_0.addRecord(bDummy, 0, 2);
  138.                }
  139.  
  140.                byte[] var5 = this.text1.getString().getBytes();
  141.                this.field_0.setRecord(1, var5, 0, var5.length);
  142.                this.sStatus = 1;
  143.             } catch (Exception var11) {
  144.             }
  145.  
  146.             try {
  147.                this.field_0.closeRecordStore();
  148.             } catch (Exception var10) {
  149.             }
  150.          }
  151.  
  152.          if (this.nStatus != var3 && var1 != this.cmCancel) {
  153.             this.initlist00();
  154.             this.display.setCurrent(this.list00);
  155.             this.list00.setCommandListener(this);
  156.          } else {
  157.             this.display.setCurrent(this.text1);
  158.             this.text1.setCommandListener(this);
  159.          }
  160.  
  161.          this.nStatus = 0;
  162.       }
  163.  
  164.    }
  165.  
  166.    protected void pauseApp() {
  167.    }
  168.  
  169.    protected void destroyApp(boolean var1) {
  170.       ((MIDlet)this).notifyDestroyed();
  171.    }
  172. }
  173.